﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
using INTEX.DataBase;
using INTEX.DataBase.Tools;
using System.Linq;
using Intex.Tools;
namespace WPFExcelReport
{
    public class SizeColorMatrix
    {
        public string Line { get; set; }
        public string Color { get; set; }
        public string Size { get; set; }
        public int Qty { get; set; }
    }

    public class YCAFS05CHGRData : BaseFunction
    {
        public INTEXDBC INTEXDBC;
        public SETINTEXDB INTEXDB = new SETINTEXDB();
        public DataSet SetCAD;
        public DataSet SetExt
        {
            get
            {
                return Convert2Intex.SetExt;
            }
            set
            {
                Convert2Intex.SetExt = value;
            }
        }
        public Convert2Intex Convert2Intex;
        public YCAFS05CHGRData()
            : base()
        {

        }
        public YCAFS05CHGRData(OracleConnection _OracleDB, IntexReptServBLClient _proxy, string userID = "        ")
            : base(_OracleDB, _proxy, userID)
        {
            INTEXDBC = new INTEXDBC(_OracleDB, _proxy);
            Convert2Intex = new Convert2Intex();
            Helpers.Helper.GetDate(ref date, ref year, ref month, ref day);
        }
        public YCAFS05CHGRData(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
            INTEXDBC = new INTEXDBC(OracleDB, proxy);
            Convert2Intex = new Convert2Intex();
            Helpers.Helper.GetDate(ref date, ref year, ref month, ref day);
        } 
        public DataSet GetSData(string art)
        {
            DataSet Result = new DataSet();
            DataSet Return = new DataSet();
            DataRow dwTemp = null;
            try
            {
                dwTemp = INTEXDB.FSSTUELI.NewRow();
                dwTemp["FSSMANDANT"] = "00";
                dwTemp["FSSMART"] = art;
                Result = INTEXDBC.QueryFSSTUELI(dwTemp, 4);
                Return.Merge(Result);             
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }
        public DataSet Convert2FSSTUELI(DataRow dwData)
        {

            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "FSSTUELI_MAP";
            DataTable tbMapID = new DataTable();

            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "FSSTUELI";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim() == "FSSTUELI"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2FDECKB(DataRow dwData)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "FDECKB_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "FDECK";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim().Trim() == "FDECK"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet Convert2WDECK(DataRow dwData)
        {
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            string mapID = "WDECK_MAP";
            DataTable tbMapID = new DataTable();
            tbMapID = SetCAD.Tables[mapID];
            DataTable tbIntex = new DataTable();
            tbIntex.TableName = "WDECK";
            DataRow dwIntex = tbIntex.NewRow();
            var query = from dwMap in tbMapID.AsEnumerable()
                        where dwMap["FILE"].ToString().Trim().Trim() == "WDECK"
                        select dwMap;
            foreach (DataRow dwTemp in query)
            {
                Convert2Intex.GetCovnertValue(ref dwIntex, dwTemp, dwData);
            }
            tbIntex.Rows.Add(dwIntex);
            setReturn.Merge(tbIntex);
            return setReturn;
        }
        public DataSet GetSProdData(DataRow dwInput)
        {
            DataSet Result = new DataSet();
            DataSet Return = new DataSet();
            DataRow dwTemp = null;
            try
            {
                dwTemp = INTEXDB.FDECK.NewRow();
                dwTemp["FDMANDANT"] = dwInput["FSSMANDANT"];
                dwTemp["FDART"] = dwInput["FSSART"];
                dwTemp["FDFILLER"] = dwInput["FSSMART"];
                Result = INTEXDBC.QueryFDECK(dwTemp, 8);
                Return.Merge(Result);
                dwTemp = INTEXDB.WDECK.NewRow();
                dwTemp["WDMANDANT"] = dwInput["FSSMANDANT"];
                dwTemp["WDART"] = dwInput["FSSART"];
                dwTemp["WDPRART"] = dwInput["FSSMART"];
                Result = INTEXDBC.QueryWDECK(dwTemp, 17);
                Return.Merge(Result);
                dwTemp = INTEXDB.ABPOS.NewRow();
                dwTemp["ABPMANDANT"] = dwInput["FSSMANDANT"];
                dwTemp["ABPART"] = dwInput["FSSART"];
                Result = INTEXDBC.QueryABPOS(dwTemp, 10);
                Return.Merge(Result);
                dwTemp = INTEXDB.ICC_ABAUFM.NewRow();
                dwTemp["ABAMANDANT"] = dwInput["FSSMANDANT"];
                dwTemp["ABAART"] = dwInput["FSSMART"];
                dwTemp["ABPART"] = dwInput["FSSART"];
                Result = INTEXDBC.QueryICC_ABAUFM(dwTemp, 26);
                Return.Merge(Result);
                dwTemp = INTEXDB.ABPOS.NewRow();
                dwTemp["ABPMANDANT"] = dwInput["FSSMANDANT"];
                dwTemp["ABPART"] = dwInput["FSSART"];
                Result = INTEXDBC.QueryABPOS(dwTemp, 17);
                Result.Tables[0].TableName = "ABPAUF";
                Return.Merge(Result);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }
        public DataSet GetSNData(DataRow dwInput)
        {
            DataSet Result = new DataSet();
            DataSet Return = new DataSet();
            DataRow dwTemp = null;
            try
            {
                dwTemp = INTEXDB.FSSTAMM.NewRow();
                dwTemp["FSMANDANT"] = dwInput["FSMANDANT"];
                dwTemp["FSART"] = dwInput["FSART"];
                Result = INTEXDBC.QueryFSSTAMM(dwTemp, 2);
                Return.Merge(Result);
                dwTemp = INTEXDB.FSSTUELI.NewRow();
                dwTemp["FSSMANDANT"] = dwInput["FSMANDANT"];
                dwTemp["FSSART"] = dwInput["FSART"];
                Result = INTEXDBC.QueryFSSTUELI(dwTemp, 2);
                Return.Merge(Result);
                dwTemp = INTEXDB.FSFARBEN.NewRow();
                dwTemp["FSFMANDANT"] = dwInput["FSMANDANT"];
                dwTemp["FSFART"] = dwInput["FSART"];
                Result = INTEXDBC.QueryFSFARBEN(dwTemp, 4);
                Return.Merge(Result);
                 dwTemp = INTEXDB.WAFARBEN.NewRow();
                dwTemp["WAFMANDANT"] = dwInput["FSMANDANT"];
                dwTemp["WAFART"] = dwInput["FSART"];
                Result = INTEXDBC.QueryWAFARBEN(dwTemp, 8);
                Result.Tables[0].TableName = "FSFARBEN";
                Return.Merge(Result); 
                dwTemp = INTEXDB.FSGROE.NewRow();
                dwTemp["FSGMANDANT"] = dwInput["FSMANDANT"];
                dwTemp["FSGART"] = dwInput["FSART"];
                Result = INTEXDBC.QueryFSGROE(dwTemp, 3);
                Return.Merge(Result); 
               
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return Return;
        }


    }
}
